<?php
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_set_option($socket,SOL_SOCKET,SO_REUSEADDR,true);
socket_bind($socket,"0.0.0.0",9999);
socket_listen($socket);
$read_sockets[] = $socket;
$write_sockets = null;
$except_sockets = null;
while (true){
  $tmp_sockets = $read_sockets;
  $count = socket_select($tmp_sockets,$write_sockets,$except_sockets,null);
  var_dump($read_sockets);
  var_dump($tmp_sockets);
  foreach ($tmp_sockets as $sock) {
      if ($sock == $socket) {
          $conSock = socket_accept($sock);
          socket_getpeername($conSock, $ip, $port);
          echo "====ip:{$ip}===port:{$port}" . PHP_EOL;
          $read_sockets[] = $conSock;
          var_dump($read_sockets);
      } else {
         $recMsg = socket_read($sock, 1024);
         socket_write($sock,strtoupper($recMsg),strlen($recMsg));
         echo $recMsg;
         var_dump($sock);
      }
  }
}